﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Extensions.Repository;
using Wq.MeetingService.Entities;
using Wq.MeetingService.Models;
using Wq.Model;

namespace Wq.MeetingService
{
    /// <summary>
    /// 品牌
    /// </summary>
    public class BrandService : SqlSugarBaseRepository<BrandInfo>, IAddSingleton
    {
        /// <summary>
        /// 品牌列表
        /// </summary>
        /// <typeparam name="VenueCategoryQuery"></typeparam>
        /// <param name="pageModel"></param>
        /// <returns></returns>
        public List<BrandInfo> List(PageModel<BrandQuery> pageModel)
        {
          
            int count = 0;
            var list = Context.Queryable<BrandInfo>()
                  .WhereIF(!SqlFunc.IsNullOrEmpty(pageModel.Entity.Name), p => p.Name.Contains(pageModel.Entity.Name))
                  .WhereIF(!SqlFunc.IsNullOrEmpty(pageModel.Entity.FirstLetter), p => p.FirstLetter == pageModel.Entity.FirstLetter)
                  .Select<BrandInfo>()
                  .OrderBy(pageModel.GetOrderbyString())
                  .ToPageList(pageModel.Page.Index, pageModel.Page.Size, ref count);
            pageModel.Page.Num = count;
            return list;
        }

        /// <summary>
        /// 修改排序
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sequence"></param>
        public void UpdateSequence(long id, long sequence) => Context.Updateable<BrandInfo>().SetColumns(p => p.Sequence == sequence).Where(p => p.Id == id).ExecuteCommand();

        /// <summary>
        /// 修改是否热门
        /// </summary>
        /// <param name="id"></param>
        /// <param name="partner"></param>
        public void UpdatePartner(long id, bool partner) => Context.Updateable<BrandInfo>().SetColumns(p => p.IsPartner == partner).Where(p => p.Id == id).ExecuteCommand();
    }
}
